package cn.xingzhe.monster.user.application.converter;

import cn.xingzhe.monster.user.application.dto.UserDTO;
import cn.xingzhe.monster.user.domain.model.UserModel;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * 用户转换器
 * 负责 UserModel 和 UserDTO 之间的转换
 *
 * @author System
 * @version 1.0.0
 * @since 2024-01-01
 */
@Mapper(componentModel = "spring")
public interface UserConverter {

    UserConverter INSTANCE = Mappers.getMapper(UserConverter.class);

    /**
     * 领域模型转DTO
     *
     * @param model 用户领域模型
     * @return 用户DTO
     */
    @Mapping(target = "roles", ignore = true)
    UserDTO toDTO(UserModel model);

    /**
     * DTO转领域模型
     *
     * @param dto 用户DTO
     * @return 用户领域模型
     */
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "password", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    UserModel fromDTO(UserDTO dto);
}

